import sqlite3

import xlrd,os
from flask import Flask, render_template

app = Flask(__name__)


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/main")
def main1():
    return render_template("index.html")


@app.route("/details")
def details():
    return render_template("details.html")


@app.route("/movie_top")
def movie_top():
    datalist = []
    try:
        path = r"{path}/豆瓣电影Top250.xls".format(path=os.path.dirname(os.path.dirname(__file__)))
        book = xlrd.open_workbook(path)  # 打开一个excel,xlrd模块中的打开sheet页的方法
        sheet = book.sheet_by_index(0)  # 打开第1个sheet
        for i in range(1, sheet.nrows):  # 获取文件所有内容
            datalist.append(sheet.row_values(i))
    except Exception as e:
        print("reading workbook hava a err: %s"%e)

    return render_template("movie_top.html",movies = datalist)



@app.route("/word_cloud")
def word_cloud():
    return render_template("word_cloud.html")


@app.route("/statistical")
def statistical():
    return render_template("statistical.html")


if __name__ == '__main__':
    app.run(port=8000, debug=True)  # 开启debug模式
